﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using DevComponents.AdvTree;
using DevComponents.DotNetBar;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.HVAC.WarmPipeSetting
{
	public partial class FrmHYStandard : HYBaseForm
	{
		public FrmHYStandard()
		{
			this.InitializeComponent();
		}

		private void FrmHYStandard_Load(object sender, EventArgs e)
		{
			try
			{
				this.InitComboBoxData();
				this.SetTreeStyle();
				this.allDataList = this.GetConfigData(this.path);
				this.RefreshDataList();
				this.SetadvTreeColumnWidth();
			}
			catch (Exception)
			{
				YJKMessageBox.Show("盈建科标准数据格式不正确！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void SetadvTreeColumnWidth()
		{
			string[] frmHYStandardHeatingText = this.userSetting.GetFrmHYStandardHeatingText();
			if (frmHYStandardHeatingText[6] != "")
			{
				base.Width = frmHYStandardHeatingText[6].ToInt(0);
			}
			if (frmHYStandardHeatingText[7] != "")
			{
				base.Height = frmHYStandardHeatingText[7].ToInt(0);
			}
			if (frmHYStandardHeatingText[0] != "")
			{
				this.colPipingType.Width.Absolute = frmHYStandardHeatingText[0].ToInt(0);
			}
			if (frmHYStandardHeatingText[1] != "")
			{
				this.colAbb.Width.Absolute = frmHYStandardHeatingText[1].ToInt(0);
			}
			if (frmHYStandardHeatingText[2] != "")
			{
				this.colLineColor.Width.Absolute = frmHYStandardHeatingText[2].ToInt(0);
			}
			if (frmHYStandardHeatingText[3] != "")
			{
				this.colLinePattern.Width.Absolute = frmHYStandardHeatingText[3].ToInt(0);
			}
			if (frmHYStandardHeatingText[4] != "")
			{
				this.colLineWeight.Width.Absolute = frmHYStandardHeatingText[4].ToInt(0);
			}
			if (frmHYStandardHeatingText[5] != "")
			{
				this.colClassify.Width.Absolute = frmHYStandardHeatingText[5].ToInt(0);
			}
		}

		private void btnAddSystem_Click(object sender, EventArgs e)
		{
			string message = "请选择新建项！";
			if (this.pipingTypeTree.SelectedNode == null)
			{
				YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo sysTypeInfo = this.pipingTypeTree.SelectedNode.Tag as SystemTypeInfo;
			if (sysTypeInfo == null)
			{
				YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo copyItem = null;
			if (sysTypeInfo.IsParent)
			{
				SystemTypeInfo systemTypeInfo = (from x in this.allDataList
				where !x.IsParent && x.GroupName == sysTypeInfo.SysType
				orderby x.SortIndex
				select x).FirstOrDefault<SystemTypeInfo>();
				if (systemTypeInfo == null)
				{
					YJKMessageBox.Show("当前分组中无有效项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					return;
				}
				copyItem = systemTypeInfo.Clone();
			}
			else
			{
				copyItem = sysTypeInfo.Clone();
			}
			SystemTypeInfo copyItem2 = copyItem;
			//copyItem2.SysType++;
			IList<string> existNames = PipeSettingManager.GetExistNames(sysTypeInfo.IsParent, this.allDataList);
			FrmAddStdType frmAddStdType = new FrmAddStdType(copyItem, existNames);
			if (frmAddStdType.ShowDialog(this) != DialogResult.OK)
			{
				return;
			}
			SystemTypeInfo newSubInfo = frmAddStdType.OutputInfo;
			if (newSubInfo == null)
			{
				return;
			}
			newSubInfo.SortIndex = copyItem.SortIndex + 1;
			newSubInfo.IsParent = false;
			foreach (SystemTypeInfo systemTypeInfo2 in ((IEnumerable<SystemTypeInfo>)(from x in this.allDataList
			where !x.IsParent && x.GroupName == newSubInfo.GroupName && x.SortIndex > copyItem.SortIndex
			select x).ToList<SystemTypeInfo>()))
			{
				systemTypeInfo2.SortIndex++;
			}
			this.allDataList.Add(newSubInfo);
			this.SaveConfigData(this.path);
			this.RefreshDataList();
			this.SelectedRow(newSubInfo);
		}

		private void btnDelSystem_Click(object sender, EventArgs e)
		{
			string message = "请选择删除项！";
			if (this.pipingTypeTree.SelectedNode == null)
			{
				YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo curSysType = this.pipingTypeTree.SelectedNode.Tag as SystemTypeInfo;
			if (curSysType == null)
			{
				YJKMessageBox.Show(message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			if (this.IsLastNode(curSysType))
			{
				YJKMessageBox.Show("至少保留一条数据！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo systemTypeInfo = null;
			if (curSysType.IsParent)
			{
				this.allDataList.RemoveAll((SystemTypeInfo x) => !x.IsParent && x.GroupName == curSysType.SysType);
				IList<SystemTypeInfo> list = (from x in this.allDataList
				where x.IsParent && x.SortIndex > curSysType.SortIndex
				orderby x.SortIndex
				select x).ToList<SystemTypeInfo>();
				if (list.Count <= 0)
				{
					systemTypeInfo = (from x in this.allDataList
					where x.IsParent && x.SysType != curSysType.SysType
					orderby x.SortIndex
					select x).FirstOrDefault<SystemTypeInfo>();
				}
				else
				{
					systemTypeInfo = list.First<SystemTypeInfo>();
				}
				foreach (SystemTypeInfo systemTypeInfo2 in list)
				{
					systemTypeInfo2.SortIndex--;
				}
				this.allDataList.Remove(curSysType);
			}
			else if (((ICollection<SystemTypeInfo>)(from x in this.allDataList
			where !x.IsParent && x.GroupName == curSysType.GroupName && x.SysType != curSysType.SysType
			select x).ToList<SystemTypeInfo>()).Count <= 0)
			{
				SystemTypeInfo parentNode = (from x in this.allDataList
				where x.IsParent && x.SysType == curSysType.GroupName
				select x).FirstOrDefault<SystemTypeInfo>();
				foreach (SystemTypeInfo systemTypeInfo3 in ((IEnumerable<SystemTypeInfo>)(from x in this.allDataList
				where x.IsParent && x.SortIndex > parentNode.SortIndex
				orderby x.SortIndex
				select x).ToList<SystemTypeInfo>()))
				{
					systemTypeInfo3.SortIndex--;
				}
				this.allDataList.Remove(curSysType);
				this.allDataList.Remove(parentNode);
			}
			else
			{
				IList<SystemTypeInfo> list2 = (from x in this.allDataList
				where !x.IsParent && x.GroupName == curSysType.GroupName && x.SortIndex > curSysType.SortIndex
				orderby x.SortIndex
				select x).ToList<SystemTypeInfo>();
				foreach (SystemTypeInfo systemTypeInfo4 in list2)
				{
					systemTypeInfo4.SortIndex--;
				}
				if (list2.Count <= 0)
				{
					systemTypeInfo = (from x in this.allDataList
					where !x.IsParent && x.GroupName == curSysType.GroupName && x.SortIndex < curSysType.SortIndex
					orderby x.SortIndex
					select x).ToList<SystemTypeInfo>().FirstOrDefault<SystemTypeInfo>();
				}
				else
				{
					systemTypeInfo = list2.First<SystemTypeInfo>();
				}
				this.allDataList.Remove(curSysType);
			}
			this.SaveConfigData(this.path);
			this.RefreshDataList();
			if (systemTypeInfo != null)
			{
				this.SelectedRow(systemTypeInfo);
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnLoad_Click(object sender, EventArgs e)
		{
			if (this.pipingTypeTree.CheckedNodes.Count <= 0)
			{
				YJKMessageBox.Show("请勾选导入项！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			SystemTypeInfo systemTypeInfo = null;
			IList<SystemTypeInfo> list = null;
			try
			{
				foreach (Node node in this.pipingTypeTree.CheckedNodes)
				{
					systemTypeInfo = (node.Tag as SystemTypeInfo);
					if (node.Nodes.Count > 0)
					{
						list = new List<SystemTypeInfo>();
						foreach (object obj in node.Nodes)
						{
							Node node2 = (Node)obj;
							if (node2.Checked)
							{
								SystemTypeInfo item = node2.Tag as SystemTypeInfo;
								list.Add(item);
							}
						}
						this.HyPipingStyle.Add(systemTypeInfo.SysType, list);
					}
					else if (this.HyPipingStyle.ContainsKey(systemTypeInfo.GroupName))
					{
						this.HyPipingStyle[systemTypeInfo.GroupName].Add(systemTypeInfo);
					}
					else
					{
						IList<SystemTypeInfo> list2 = new List<SystemTypeInfo>();
						list2.Add(systemTypeInfo);
						this.HyPipingStyle.Add(systemTypeInfo.GroupName, list2);
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("获取选择项错误！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			base.DialogResult = DialogResult.OK;
		}

		public void RefreshDataList()
		{
			this.pipingTypeTree.Nodes.Clear();
			this.pipingTypeTree.BeginUpdate();
			this.InitTree();
			this.pipingTypeTree.EndUpdate();
		}

		private void InitTree()
		{
			System.Drawing.Color empty = System.Drawing.Color.Empty;
            IEnumerator<SystemTypeInfo> enumerator = ((IEnumerable<SystemTypeInfo>)(from x in this.allDataList
                                                                                    where x.IsParent
                                                                                    orderby x.SortIndex
                                                                                    select x).ToList<SystemTypeInfo>()).GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					SystemTypeInfo parent = enumerator.Current;
					IEnumerable<SystemTypeInfo> enumerable = (from x in this.allDataList
					where !x.IsParent && x.GroupName == parent.SysType
					orderby x.SortIndex
					select x).ToList<SystemTypeInfo>();
					Node node = new Node(parent.SysType);
					node.Tag = parent;
					node.CheckBoxVisible = true;
					node.CheckBoxThreeState = true;
					node.Expand();
					node.Cells.Add(new Cell());
					node.Cells.Add(new Cell());
					node.Cells.Add(new Cell());
					node.Cells.Add(new Cell());
					node.Cells.Add(new Cell());
					node.Cells.Add(new Cell());
					node.Cells.Add(new Cell());
					foreach (SystemTypeInfo systemTypeInfo in enumerable)
					{
						Node node2 = new Node(systemTypeInfo.SysType);
						node2.Tag = systemTypeInfo;
						node2.CheckBoxVisible = true;
						ElementStyle styleNormal = new ElementStyle(SystemManageHelper.getXMLDataColor(systemTypeInfo.LineColor));
						node2.Cells.Add(new Cell(systemTypeInfo.Abbreviation));
						node2.Cells.Add(new Cell(systemTypeInfo.PipeType));
						node2.Cells.Add(new Cell(systemTypeInfo.LineColor, styleNormal));
						node2.Cells.Add(new Cell(systemTypeInfo.LinePattern));
						node2.Cells.Add(new Cell(systemTypeInfo.LineWeight));
						node2.Cells.Add(new Cell(systemTypeInfo.SysCategory));
						node2.Cells.Add(new Cell(systemTypeInfo.GroupName));
						node.Nodes.Add(node2);
					}
					this.pipingTypeTree.Nodes.Add(node);
				}
			}
		}

		private void SelectedRow(SystemTypeInfo selectedItem)
		{
			if (this.pipingTypeTree.Nodes.Count <= 0)
			{
				return;
			}
			if (selectedItem == null)
			{
				return;
			}
			foreach (object obj in this.pipingTypeTree.Nodes)
			{
				Node node = (Node)obj;
				if (node.Tag as SystemTypeInfo == selectedItem)
				{
					node.Expand();
					this.pipingTypeTree.SelectedNode = node;
					break;
				}
				foreach (object obj2 in node.Nodes)
				{
					Node node2 = (Node)obj2;
					if (node2.Tag as SystemTypeInfo == selectedItem)
					{
						node.Expand();
						this.pipingTypeTree.SelectedNode = node2;
						return;
					}
				}
			}
		}

		private List<SystemTypeInfo> GetConfigData(string filePath)
		{
			if (!File.Exists(filePath))
			{
				File.Copy(Path.Combine(Product.DataLocation, "User\\HYWarmPipingTypeInfo.xml"), filePath, true);
			}
			SystemTypeXmlHelper systemTypeXmlHelper = new SystemTypeXmlHelper(filePath);
			string xpath = string.Format("styleNode[@name='{0}']/system[@name='{1}']/add", PipeSettingManager.HyStandardStyle, PipeSettingManager.SystemName);
			IEnumerable<SystemTypeInfo> pipingSystemType = systemTypeXmlHelper.GetPipingSystemType(xpath);
			IDictionary<string, IList<SystemTypeInfo>> dictionary = new Dictionary<string, IList<SystemTypeInfo>>();
			foreach (SystemTypeInfo systemTypeInfo in pipingSystemType)
			{
				if (dictionary.ContainsKey(systemTypeInfo.GroupName))
				{
					dictionary[systemTypeInfo.GroupName].Add(systemTypeInfo);
				}
				else
				{
					IList<SystemTypeInfo> list = new List<SystemTypeInfo>();
					list.Add(systemTypeInfo);
					dictionary.Add(systemTypeInfo.GroupName, list);
				}
			}
			return PipeSettingManager.CreateGroupNode(dictionary);
		}

		public void SaveConfigData(string filePath)
		{
			try
			{
				string xpath = "styleNode/system";
				SystemTypeXmlHelper systemTypeXmlHelper = new SystemTypeXmlHelper(filePath);
				XmlDocument xmlDoc = systemTypeXmlHelper.XmlDoc;
				XmlElement xmlElement = xmlDoc.DocumentElement.SelectSingleNode(xpath) as XmlElement;
				xmlElement.RemoveAll();
				xmlElement.SetAttribute("name", "暖管系统类型");
				IEnumerator<SystemTypeInfo> enumerator = ((IEnumerable<SystemTypeInfo>)(from x in this.allDataList
				where x.IsParent
				orderby x.SortIndex
				select x).ToList<SystemTypeInfo>()).GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						SystemTypeInfo parent = enumerator.Current;
						foreach (SystemTypeInfo systemTypeInfo in ((IEnumerable<SystemTypeInfo>)(from x in this.allDataList
						where !x.IsParent && x.GroupName == parent.SysType
						orderby x.SortIndex
						select x).ToList<SystemTypeInfo>()))
						{
							XmlElement newChild = systemTypeXmlHelper.CreateNode("add", new Hashtable
							{
								{
									"pipingSystemType",
									systemTypeInfo.SysType
								},
								{
									"pipingSystemTypeAbb",
									systemTypeInfo.Abbreviation
								},
								{
									"pipeType",
									systemTypeInfo.PipeType
								},
								{
									"lineColor",
									systemTypeInfo.LineColor
								},
								{
									"linePattern",
									systemTypeInfo.LinePattern
								},
								{
									"lineWeight",
									systemTypeInfo.LineWeight
								},
								{
									"rPipeRadius",
									50
								},
								{
									"pipingClassify",
									systemTypeInfo.SysCategory
								},
								{
									"group",
									systemTypeInfo.GroupName
								}
							});
							xmlElement.AppendChild(newChild);
						}
					}
				}
				xmlDoc.Save(filePath);
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				YJKMessageBox.Show("保存数据出错！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void InitComboBoxData()
		{
			this.linePatternList = PipeSettingManager.GetLinePatternName();
			this.lineWeightList = PipeSettingManager.GetLineWeight();
			this.pipeClassifyList = PipeSettingManager.PipingClassify;
			this.pipeTypeList = PipeSettingManager.GetPipeTypeNames();
		}

		private void FillData(System.Windows.Forms.ComboBox column, IList<string> dataList)
		{
			column.Items.Clear();
			if (dataList == null)
			{
				return;
			}
			foreach (string item in dataList)
			{
				column.Items.Add(item);
			}
		}

		private void SetTreeStyle()
		{
			this.pipingTypeTree.CellEdit = true;
			this.pipingTypeTree.FullRowSelect = false;
			this.pipingTypeTree.ShowToolTips = true;
			this.pipingTypeTree.GridRowLines = true;
			this.pipingTypeTree.GridColumnLines = true;
			this.pipingTypeTree.GridLinesColor = System.Drawing.Color.Silver;
		}

		private void ShowColorDialog(string colorStr, Cell cell)
		{
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.AllowFullOpen = true;
			colorDialog.FullOpen = true;
			System.Drawing.Color xmldataColor = SystemManageHelper.getXMLDataColor(colorStr);
			if (!xmldataColor.IsKnownColor)
			{
				int[] array = new int[16];
				array[0] = SystemManageHelper.GetIntAboutColor(xmldataColor);
				colorDialog.CustomColors = array;
			}
			colorDialog.Color = xmldataColor;
			DialogResult dialogResult = colorDialog.ShowDialog();
			if (DialogResult.OK == dialogResult)
			{
				string newRGB = SystemManageHelper.getNewRGB(colorDialog.Color.R);
				string newRGB2 = SystemManageHelper.getNewRGB(colorDialog.Color.G);
				string newRGB3 = SystemManageHelper.getNewRGB(colorDialog.Color.B);
				string str = string.Concat(new string[]
				{
					"RGB ",
					newRGB.ToString(),
					" ",
					newRGB2.ToString(),
					" ",
					newRGB3.ToString()
				});
				cell.Text = "█" + str;
				cell.StyleNormal.TextColor = colorDialog.Color;
				SystemTypeInfo systemTypeInfo = cell.Parent.Tag as SystemTypeInfo;
				if (systemTypeInfo == null)
				{
					return;
				}
				systemTypeInfo.LineColor = cell.Text;
				this.SaveConfigData(this.path);
			}
		}

		private void cbbContainer_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cellSelected == null)
			{
				return;
			}
			string text = this.cbbContainer.SelectedItem.ToString();
			SystemTypeInfo systemTypeInfo = this.cellSelected.Parent.Tag as SystemTypeInfo;
			string name = this.cellSelected.ColumnHeader.Name;
			if (!(name == "colLinePattern"))
			{
				if (!(name == "colLineWeight"))
				{
					if (name == "colClassify")
					{
						systemTypeInfo.SysCategory = text;
					}
				}
				else
				{
					systemTypeInfo.LineWeight = text;
				}
			}
			else
			{
				systemTypeInfo.LinePattern = text;
			}
			this.cellSelected.Text = text;
			this.SaveConfigData(this.path);
		}

		private void pipingTypeTree_BeforeCellEdit(object sender, CellEditEventArgs e)
		{
			Cell cell = e.Cell;
			if (cell.Parent.Level == 0)
			{
				this.cbbContainer.Visible = false;
				e.Cell.Editable = false;
				e.Cancel = true;
				return;
			}
			string text = cell.Text;
			System.Drawing.Rectangle bounds = cell.Bounds;
			string name = cell.ColumnHeader.Name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 2835151868u)
			{
				if (num != 1705371435u)
				{
					if (num != 2005745351u)
					{
						if (num != 2835151868u)
						{
							return;
						}
						if (!(name == "colAbb"))
						{
							return;
						}
					}
					else
					{
						if (!(name == "colLineWeight"))
						{
							return;
						}
						this.cellSelected = cell;
						this.FillData(this.cbbContainer, this.lineWeightList);
						this.cbbContainer.Items.Insert(0, "默认");
						this.cbbContainer.SelectedItem = text;
						this.cbbContainer.Width = bounds.Width + 2;
						this.cbbContainer.Height = bounds.Height - 3;
						this.cbbContainer.Top = bounds.Top - 2;
						this.cbbContainer.Left = bounds.Left - 2;
						this.cbbContainer.Visible = true;
						e.Cancel = true;
						return;
					}
				}
				else
				{
					if (!(name == "colClassify"))
					{
						return;
					}
					this.cellSelected = cell;
					this.FillData(this.cbbContainer, this.pipeClassifyList);
					this.cbbContainer.SelectedItem = text;
					this.cbbContainer.Width = bounds.Width + 2;
					this.cbbContainer.Height = bounds.Height - 3;
					this.cbbContainer.Top = bounds.Top - 2;
					this.cbbContainer.Left = bounds.Left - 2;
					this.cbbContainer.Visible = true;
					e.Cancel = true;
					return;
				}
			}
			else if (num <= 2987288598u)
			{
				if (num != 2971373733u)
				{
					if (num != 2987288598u)
					{
						return;
					}
					if (!(name == "colPipingType"))
					{
						return;
					}
				}
				else
				{
					if (!(name == "colPipeType"))
					{
						return;
					}
					this.cellSelected = cell;
					this.FillData(this.cbbContainer, this.pipeTypeList);
					this.cbbContainer.SelectedItem = text;
					this.cbbContainer.Width = bounds.Width + 2;
					this.cbbContainer.Height = bounds.Height - 3;
					this.cbbContainer.Top = bounds.Top - 2;
					this.cbbContainer.Left = bounds.Left - 2;
					this.cbbContainer.Visible = true;
					e.Cancel = true;
					return;
				}
			}
			else if (num != 3786413770u)
			{
				if (num != 3800690131u)
				{
					return;
				}
				if (!(name == "colLinePattern"))
				{
					return;
				}
				this.cellSelected = cell;
				this.FillData(this.cbbContainer, this.linePatternList);
				this.cbbContainer.Items.Insert(0, "默认");
				this.cbbContainer.SelectedItem = text;
				this.cbbContainer.Width = bounds.Width + 2;
				this.cbbContainer.Height = bounds.Height - 3;
				this.cbbContainer.Top = bounds.Top - 2;
				this.cbbContainer.Left = bounds.Left - 2;
				this.cbbContainer.Visible = true;
				e.Cancel = true;
				return;
			}
			else
			{
				if (!(name == "colLineColor"))
				{
					return;
				}
				this.ShowColorDialog(text, cell);
				e.Cancel = true;
				return;
			}
			this.cbbContainer.Visible = false;
		}

		private void pipingTypeTree_AfterCellEdit(object sender, CellEditEventArgs e)
		{
			Cell cell = e.Cell;
			Node parent = cell.Parent;
			if (parent == null)
			{
				return;
			}
			string newText = e.NewText;
			SystemTypeInfo systemTypeInfo = parent.Tag as SystemTypeInfo;
			string name = cell.ColumnHeader.Name;
			if (!(name == "colPipingType"))
			{
				if (!(name == "colAbb"))
				{
					return;
				}
				systemTypeInfo.Abbreviation = newText;
				this.SaveConfigData(this.path);
				return;
			}
			else
			{
				IList<string> existNames = PipeSettingManager.GetExistNames(systemTypeInfo.IsParent, this.allDataList);
				existNames.Remove(systemTypeInfo.SysType);
				if (existNames.Contains(newText))
				{
					YJKMessageBox.Show("已存在相同名称的系统类型!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					e.Cancel = true;
					return;
				}
				systemTypeInfo.SysType = newText;
				this.SaveConfigData(this.path);
				return;
			}
		}

		private void pipingTypeTree_BeforeCheck(object sender, AdvTreeCellBeforeCheckEventArgs e)
		{
			if (this.autoSetChecked)
			{
				return;
			}
			Node parent = e.Cell.Parent;
			bool flag = !parent.Checked;
			if (parent.Level != 0)
			{
				CheckState checkState = CheckState.Unchecked;
				Node parent2 = parent.Parent;
				foreach (object obj in parent2.Nodes)
				{
					Node node = (Node)obj;
					if (node != parent && node.Checked != flag)
					{
						checkState = CheckState.Indeterminate;
						break;
					}
				}
				if (checkState != CheckState.Indeterminate)
				{
					checkState = (parent.Checked ? CheckState.Unchecked : CheckState.Checked);
				}
				this.autoSetChecked = true;
				parent2.CheckState = checkState;
				this.autoSetChecked = false;
				return;
			}
			parent.Expand();
			foreach (object obj2 in parent.Nodes)
			{
				Node node2 = (Node)obj2;
				this.autoSetChecked = true;
				node2.Checked = !parent.Checked;
				this.autoSetChecked = false;
			}
			if (parent.Checked)
			{
				this.autoSetChecked = true;
				parent.CheckState = CheckState.Unchecked;
				e.Cancel = true;
				this.autoSetChecked = false;
				return;
			}
			this.autoSetChecked = true;
			parent.CheckState = CheckState.Checked;
			e.Cancel = true;
			this.autoSetChecked = false;
		}

		private void pipingTypeTree_Leave(object sender, EventArgs e)
		{
			this.cbbContainer.Visible = false;
		}

		private void pipingTypeTree_MouseWheel(object sender, MouseEventArgs e)
		{
			this.cbbContainer.Visible = false;
		}

		private void cbbContainer_Leave(object sender, EventArgs e)
		{
			this.cbbContainer.Visible = false;
		}

		private void pipingTypeTree_Scroll(object sender, ScrollEventArgs e)
		{
			this.cbbContainer.Visible = false;
		}

		private void cbbContainer_DropDown(object sender, EventArgs e)
		{
			PipeSettingManager.AdjustComboBoxDropDownListWidth(this.cbbContainer);
		}

		private bool IsLastNode(SystemTypeInfo sysType)
		{
			if (sysType == null)
			{
				throw new Exception("出现异常！");
			}
			if (sysType.IsParent)
			{
				if (((ICollection<SystemTypeInfo>)(from x in this.allDataList
				where x.IsParent && x.SysType != sysType.SysType
				select x).ToList<SystemTypeInfo>()).Count <= 0)
				{
					return true;
				}
			}
			else if (((ICollection<SystemTypeInfo>)(from x in this.allDataList
			where x.IsParent && x.SysType != sysType.GroupName
			select x).ToList<SystemTypeInfo>()).Count <= 0 && ((ICollection<SystemTypeInfo>)(from x in this.allDataList
			where !x.IsParent && x.GroupName == sysType.GroupName && x.SysType != sysType.SysType
			select x).ToList<SystemTypeInfo>()).Count <= 0)
			{
				return true;
			}
			return false;
		}

		private void FrmHYStandard_FormClosing(object sender, FormClosingEventArgs e)
		{
			string[] texts = new string[]
			{
				this.colPipingType.Width.Absolute.ToString(),
				this.colAbb.Width.Absolute.ToString(),
				this.colLineColor.Width.Absolute.ToString(),
				this.colLinePattern.Width.Absolute.ToString(),
				this.colLineWeight.Width.Absolute.ToString(),
				this.colClassify.Width.Absolute.ToString(),
				base.Width.ToString(),
				base.Height.ToString()
			};
			this.userSetting.WriteFrmHYStandardHeatingText(texts);
		}

		private bool autoSetChecked;

		private Cell cellSelected;

		private IList<string> linePatternList;

		private IList<string> lineWeightList;

		private IList<string> pipeClassifyList;

		private IList<string> pipeTypeList;

		private List<SystemTypeInfo> allDataList = new List<SystemTypeInfo>();

		private HVACUserSetting userSetting = new HVACUserSetting();

		private readonly string path = Path.Combine(Product.UserDataLocation, "HYWarmPipingTypeInfo.xml");

		public IDictionary<string, IList<SystemTypeInfo>> HyPipingStyle = new Dictionary<string, IList<SystemTypeInfo>>();
	}
}
